from .views import *

class RegionsDeal(APIView):
    def get(self, request):
        res = {}
        with open('./static/regions.csv', 'r', encoding='utf-8') as f:
            ret = f.readlines()
        p_list = []
        c_list = []
        for i in ret:
            item = i.split(',')[1:5]
            p = item[0:2]
            c = item[2:4]
            if not p in p_list:
                p_code = p[0][0:2]
                p_region = p[1]
                Region(code= p_code, region= p_region).save()
                p_list.append(p)
            if not c in c_list:
                c_code = c[0][2:4]
                c_upgrade = c[0][0:2]
                c_region = c[1]
                Region(code= c_code, region= c_region, upgrade= c_upgrade).save()
                c_list.append(c)
        # print(p_list)
        # print(c_list)
        return Response(res)